package cn.bsuc.crm.service.impl;

import cn.bsuc.crm.entity.SaleChance;
import cn.bsuc.crm.entity.User;
import cn.bsuc.crm.mapper.SaleChanceMapper;
import cn.bsuc.crm.service.SaleChanceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhuoyuan
 * @since 2022-10-03
 */
@Service
public class SaleChanceServiceImp extends ServiceImpl<SaleChanceMapper, SaleChance> implements SaleChanceService {


    @Override
    public Page<SaleChance> selectAllchance(Integer pageNo, Integer pageSize) {
        Page<SaleChance> objectPage = new Page<>(pageNo, pageSize);
        QueryWrapper<SaleChance> saleChanceQueryWrapper = new QueryWrapper<>();
        Page<SaleChance> userPage = baseMapper.selectPage(objectPage,saleChanceQueryWrapper);
        return userPage;
    }

    @Override
    public int saveChance(SaleChance saleChance) {
        if (saleChance.getId()==null){
            if(saleChance.getAssignMan()==null){
                saleChance.setState(0);
                saleChance.setDevResult(0);
            }
                saleChance.setState(1);
                saleChance.setDevResult(2);
            int insert = baseMapper.insert(saleChance);
            return insert;
        }
        int i = baseMapper.updateById(saleChance);
        return i;
    }
}
